package com.yellowpage.ndc.service;

import java.util.List;
import java.util.Map;

import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.DefaultTransactionDefinition;

import com.yellowpage.white.common.Constants;
import com.yellowpage.white.common.PageRender;
import com.yellowpage.white.dao.QueryAssistantSQL;
import com.yellowpage.white.service.BaseServiceImpl;

import com.yellowpage.ndc.data.ProdCustomerHis;
import com.yellowpage.ndc.dao.ProdCustomerHisDao;

public class ProdCustomerHisServiceImpl extends BaseServiceImpl implements ProdCustomerHisService {
	  private ProdCustomerHisDao prodCustomerHisDao;
	
	  public void setProdCustomerHisDao(ProdCustomerHisDao prodCustomerHisDao) {
		  this.prodCustomerHisDao = prodCustomerHisDao;
	  }
	
	
	  /* Smooth generate Method */ 
	  public ProdCustomerHis getProdCustomerHis(Long id){
	      return prodCustomerHisDao.get(id);
	  }
	  
    public List<ProdCustomerHis> getAllProdCustomerHis(){
        return prodCustomerHisDao.getAll();
    }
    
    public List<Map> queryProdCustomerHisByPage(Map queryMap, PageRender pageRender) {		
        
		QueryAssistantSQL sqlAssistant = baseDao.newQueryAssistantSQL(
				"SELECT c.CONTENT,c.CREATE_TIME,c.CUSTOMER_ID, case c.TYPE  when 1 then '修改' when 2 then '删除' when 3 then '360下线' when 4 then '删除还原' else '新增' end AS CREATETYPE ,u.`NAME`,u.DISPLAY_NAME,p.NAME1,p.CUST_ID  FROM NDC_PROD_CUSTOMER_HIS AS c LEFT JOIN CA_USER as u ON u.USER_ID = c.CREATE_USER LEFT JOIN db_ndc.PROD_CUSTOMER AS p ON p.ID = c.CUSTOMER_ID  WHERE 1=1 ")
				    			.addCondition(" and c.TYPE = :type ")
							    			.addCondition(" and date_format(c.CREATE_TIME,'%Y-%m-%d') >= :timeStart ")
							    			.addCondition(" and date_format(c.CREATE_TIME,'%Y-%m-%d') <= :timeEnd ")
		    				    			.addCondition(" and u.NAME LIKE :userName ")
							    			.addCondition(" and u.DISPLAY_NAME LIKE :displayName ")
							    			.addCondition(" and p.CUST_ID LIKE :customerCode ")
							    			.addCondition(" and p.NAME1 LIKE :customerName ")
							    ; 		    
		    

		List<Map> resultList = sqlAssistant.queryByPage(
				baseDao.getConnection(), queryMap, pageRender);

		return resultList;
	}
    
    
    public void saveProdCustomerHis(ProdCustomerHis prodCustomerHis){
        prodCustomerHisDao.save(prodCustomerHis);
    }
    
	  public void updateProdCustomerHis(ProdCustomerHis prodCustomerHis){
	      prodCustomerHisDao.update(prodCustomerHis);
	  }
	  
	  public void delete(List deleteList){
	      prodCustomerHisDao.remove(deleteList);
	  }
	  
	  
	 
	
}	